import Dialog from "./index.vue";
import { h, render } from "vue";

let createMount = (opts) => {
  const mountNode = document.createElement("div");
  document.body.appendChild(mountNode);
  const vnode = h(Dialog, {
    ...opts,
    modelValue: true,
    remove() {
      document.body.removeChild(mountNode);
    },
  });
  vnode.appContext = Modal._context;
  render(vnode, mountNode);
};
const Modal = {
  install(app, options) {
    app.config.globalProperties.$dialog2 = {
      show: (title, component, options = {}, params) => {
        options.id = options.id || "v3popup_" + 1; //唯一id 删除组件时用于定位
        createMount({
          title,
          comps: component,
        });
      },
    };
  },
  _context: null,
};
export default Modal;